package com.newdriver.edu.inf.manager.service;

import com.newdriver.edu.inf.manager.dao.TeacherDao;
import com.newdriver.edu.inf.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    public boolean isExists(String id) {
        Teacher[] teacher=teacherDao.findAllTeacher();
        boolean exists =false;
        for (int i = 0; i < teacher.length; i++) {
            Teacher teachers = teacher[i];
            if (teachers!=null && teachers.getId().equals(id)) {
                exists=true;
                break;
            }
        }
        return exists;
    }

    public boolean addTeacher(Teacher teacher) {

        return teacherDao.addTeacher(teacher);
    }


    public void deleteTeaById(String delId) {
        TeacherDao teacherDao = new TeacherDao();
        teacherDao.deleteTeaById(delId);
    }

    public void updateTeacher(String updateId, Teacher teacher) {
           teacherDao.updateTeacher(updateId,teacher);
    }

    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = teacherDao.findAllTeacher();

        boolean flag = false;
        for (int i = 0; i < allTeacher.length; i++) {
            Teacher teacher = allTeacher[i];
            if (teacher != null) {
                flag=true;
                break;
            }
        }
        if (flag) {
            return allTeacher;
        }
        return null;
    }
}
